<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
	template="/WEB-INF/templates/template.xhtml">
    <ui:define name="content">
    <h:form id="form" align="center">
		<div id="block" align="center" style="width : 800px; font-size: 10pt" >
		<p:panel id="panel">
		<h:messages/>
		<p:panel>
		<f:facet name="header">
    		<h:outputText value="Find Prescription by Prescripiton Order ID" />
		</f:facet>
    	<h:panelGrid columns="3">
    				<h:outputText value="Patient Order Id: " />
        			<p:inputText value="#{findOrderBean.patientOrderId}" id="id"  />
        			<h:commandButton action="#{findOrderBean.searchById}" value="Search" update="prescriptions" process="@this,id"/>
    	</h:panelGrid>
    	</p:panel>
    	<br />
    	<p:panel>
    	<f:facet name="header">
    		<h:outputText value="Find prescription by patient" />
		</f:facet>
    	<h:panelGrid columns="7" >
    				<h:outputText value="First Name: " />
        			<p:inputText value="#{findOrderBean.patient.firstName}" id="firstname"  />
        			<h:outputText value="Last Name: " />
        			<p:inputText value="#{findOrderBean.patient.lastName}" id="lastname"  />
        			<h:outputText value="Date of Birth: " />
        			<p:calendar value="#{findOrderBean.patient.dob}" id="dob" />  
        			<h:commandButton action="#{findOrderBean.searchByPatient}" value="Search" update="prescriptions" process="@this,firstname,lastname,dob"/>
    	</h:panelGrid>
    	</p:panel>
    	
    	<br />
    	<p:panel>
    	<f:facet name="header">
    		<h:outputText value="Find prescription by status" />
		</f:facet>
    	<h:panelGrid coulumns="3">
    		<h:outputText value="Status: " />
    		<p:selectOneMenu  value="#{findOrderBean.status}" required="true" id="status" >
        				<f:selectItem itemLabel="Open" itemValue="Open"/>
        				<f:selectItem  itemLabel="Closed" itemValue="Closed"/>
        				<f:selectItem  itemLabel="Prepared" itemValue="Prepared"/>
        				<f:selectItem itemLabel="Confirmed" itemValue="Confirmed"/>
        				<f:selectItem  itemLabel="Awaiting Confirmation" itemValue="Awaiting Confirmation"/>
        	</p:selectOneMenu>
    		<h:commandButton action="#{findOrderBean.searchByStatus}" value="Search" update="prescriptions" process="@this,status" />
    	</h:panelGrid>
    	</p:panel>
    	<br />
        	<p:dataTable id="prescriptions" var="curprescriptions" value="#{findOrderBean.patientOrderList}"  paginator="true" rows="10" >  
  
        		<p:column headerText="Prescription Order Id" style="width:5%">  
            		<h:outputText value="#{curprescriptions.patientOrderId}" />  
        		</p:column>  
  
        		<p:column headerText="First Name" style="width:15%">  
            		<h:outputText value="#{curprescriptions.patientFirstName}" />  
    	    	</p:column>  
  	
        		<p:column headerText="Last Name" style="width:15%">  
            		<h:outputText value="#{curprescriptions.patientLastName}" />  
        		</p:column>
        		
        		<p:column headerText="Order Status" style="width:10%">  
            		<h:outputText value="#{curprescriptions.status}" />  
        		</p:column>  
        		
        		<p:column headerText="Open Date" style="width:20%">  
            		<h:outputText value="#{curprescriptions.orderDate}" />  
        		</p:column>
        		
        		 <p:column headerText="Closed Date" style="width:15%">  
            		<h:outputText value="#{curprescriptions.closedDate}" />  
        		</p:column>
        		
        		<p:column style="width:10%">  
                	<h:commandButton id="updateButton" action="#{findOrderBean.updateOrder}" rendered="#{findOrderBean.action == 'update'}" value="Update">  
                	<f:setPropertyActionListener value="#{curprescriptions}" target="#{findOrderBean.patientOrder}" /> 
    				<f:param name="patientId" value="#{curprescriptions.patientId}" />
    				<f:param name="patientOrderId" value="#{curprescriptions.patientOrderId}"/>
    				<f:param name="action" value="#{findOrderBean.action}" />
            		</h:commandButton>
            		<h:commandButton id="findButton" action="#{findOrderBean.viewOrder}" rendered="#{findOrderBean.action == 'find'}" value="View">  
                	<f:setPropertyActionListener value="#{curprescriptions}" target="#{findOrderBean.patientOrder}" /> 
    				<f:param name="patientId" value="#{curprescriptions.patientId}" />
    				<f:param name="patientOrderId" value="#{curprescriptions.patientOrderId}"/>
    				<f:param name="action" value="#{findOrderBean.action}" />
            		</h:commandButton>
            		<h:commandButton id="deleteButton" action="#{findOrderBean.deleteOrder}" rendered="#{findOrderBean.action == 'delete'}" value="Delete">  
                	<f:setPropertyActionListener value="#{curprescriptions}" target="#{findOrderBean.patientOrder}" /> 
    				<f:param name="patientId" value="#{curprescriptions.patientId}" />
    				<f:param name="patientOrderId" value="#{curprescriptions.patientOrderId}"/>
    				<f:param name="action" value="#{findOrderBean.action}" />
            		</h:commandButton>
       	 		</p:column>  
  
    	</p:dataTable>  
        	
    		</p:panel>
		</div>

		</h:form>

    </ui:define>
</ui:composition>
